﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL.DateSet.GoodsTableAdapters;
using DAL.DateSet;
using DAL;
using System.Data;
namespace BLL.Wrapper
{
    public class GoodsWrapper : GoodsTableAdapter
    {
        public Goods.GoodsDataTable getall()
        {
            return GetData();
        }

        public void addARecord(Goods.GoodsRow row)
        {
            Insert(row.typeID, row.brandID, row.goodsName, row.goodsType, row.goodsLocation, row.packageCount,row.goodsPackage,row.goodsMaterial,
                   row.goodsStyle, row.goodsBill, row.goodsGuaranteePeriod, row.goodsCityService, row.goodsUnit, row.goodsCreator, row.goodsCreateDate);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from Goods where goodsID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.delete(sql);
        }

        public void updateARecord(Goods.GoodsRow row)
        {
            Goods.GoodsDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["goodsID"]) == row.goodsID)
                {
                    table.Rows[i]["typeID"] = row.typeID;
                    table.Rows[i]["brandID"] = row.brandID;
                    table.Rows[i]["goodsName"] = row.goodsName;
                    table.Rows[i]["goodsType"] = row.goodsType;

                    table.Rows[i]["goodsLocation"] = row.goodsLocation;
                    table.Rows[i]["packageCount"] = row.packageCount;
                    table.Rows[i]["goodsPackage"] = row.goodsPackage;
                    table.Rows[i]["goodsMaterial"] = row.goodsMaterial;

                    table.Rows[i]["goodsStyle"] = row.goodsStyle;
                    table.Rows[i]["goodsBill"] = row.goodsBill;
                    table.Rows[i]["goodsGuaranteePeriod"] = row.goodsGuaranteePeriod;
                    table.Rows[i]["goodsCityService"] = row.goodsCityService;

                    table.Rows[i]["goodsUnit"] = row.goodsUnit;
                    table.Rows[i]["goodsCreator"] = row.goodsCreator;
                    table.Rows[i]["goodsCreateDate"] = row.goodsCreateDate;
                    break;
                }
            }
            Update(table);
        }

        public DataTable getResultByName(string name)
        {
            string sql = "select * from Goods where goodsName = '" + name + "'";
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            return helper.getResultBySql(sql);
        }

        public DataTable getResultByType(string type)
        {
            string sql = "select * from Goods where goodsType = '" + type + "'";
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            return helper.getResultBySql(sql);
        }

        public DataTable getResultByNameAndType(string name, string type)
        {
            string sql = "select * from Goods where goodsName = '" + name + "' and goodsType = '" + type.ToString() + "'" ;
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            return helper.getResultBySql(sql);
        }

       /* public Goods.GoodsRow getGoodsByID(int id)
        {
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            DataTable table = new DataTable();
            Goods.GoodsDataTable goodstable = new Goods.GoodsDataTable();
            Goods.GoodsRow row = table.NewGoodsRow();
            string sql = "select * from Goods where goodsID = " + id.ToString();
            table = helper.getResultBySql(sql);


            table.Rows[i]["typeID"] = row.typeID;
            table.Rows[i]["brandID"] = row.brandID;
            table.Rows[i]["goodsName"] = row.goodsName;
            table.Rows[i]["goodsType"] = row.goodsType;

            table.Rows[i]["goodsLocation"] = row.goodsLocation;
            table.Rows[i]["packageCount"] = row.packageCount;
            table.Rows[i]["goodsPackage"] = row.goodsPackage;
            table.Rows[i]["goodsMaterial"] = row.goodsMaterial;

            table.Rows[i]["goodsStyle"] = row.goodsStyle;
            table.Rows[i]["goodsBill"] = row.goodsBill;
            table.Rows[i]["goodsGuaranteePeriod"] = row.goodsGuaranteePeriod;
            table.Rows[i]["goodsCityService"] = row.goodsCityService;

            table.Rows[i]["goodsUnit"] = row.goodsUnit;
            table.Rows[i]["goodsInstallCost"] = row.goodsInstallCost;
            table.Rows[i]["goodsCreator"] = row.goodsCreator;
            table.Rows[i]["goodsCreateDate"] = row.goodsCreateDate;
        }*/
    }
}
